package com.ms.p2p.controller.admin;


import com.alibaba.dubbo.config.annotation.Reference;
import com.ms.common.bean.Message;
import com.ms.p2p.bean.PageBean;
import com.ms.p2p.controller.BaseController;
import com.ms.p2p.provider.SmsRecordProvider;
import com.ms.p2p.utils.JsonDataGridHelper;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

@Controller
@RequestMapping({"/admin/smslog"})
public class AdminSmsMessageController extends AdminBaseController {

	@Reference
	private SmsRecordProvider smsRecordProvider;

	/**
	 * 获取短信记录
	 * @param request
	 * @param session
	 * @param page
	 * @return
	 */
	@RequestMapping(value = {"/queryData"}, produces = {"application/json;charset=UTF-8"})
	@ResponseBody
	public PageBean queryData(HttpServletRequest request, HttpSession session
			, @RequestParam(value = "mobilePhone",required = false) String mobilePhone
			, @RequestParam(value = "begin_date",required = false) String begin_date
			, @RequestParam(value = "end_date",required = false) String end_date
							  ,PageBean page
	) {
		page.setList(smsRecordProvider.findPager(mobilePhone,begin_date,end_date,page));
		page.setTotalCount(smsRecordProvider.findCount(mobilePhone,begin_date,end_date));
		return JsonDataGridHelper.createJSONData(page);
	}

	
	@RequestMapping({"/list"})
	public String list(){
		return "admin/system/sms_list";
	}

	@RequestMapping(value = {"/queryData"})
	@ResponseBody
	public PageBean queryData(String mobilePhone, String begin_date,String end_date,PageBean page
	) {
		page.setList(smsRecordProvider.findPager(mobilePhone,begin_date,end_date,page));
		page.setTotalCount(smsRecordProvider.findCount(mobilePhone,begin_date,end_date));
		return JsonDataGridHelper.createJSONData(page);
	}
	
	@RequestMapping("/delete")
	@ResponseBody
	public Message delete(String ids){
		smsRecordProvider.deleteByIds(ids);
		return Message.success("删除成功");
	}

	@Override
	public boolean getBinderFlag() {
		return true;
	}
}
